<script setup>
import { ref,  onMounted } from 'vue'
import axios from "axios";
let pageNum = ref(1)
let pageSize = ref(5)
let total = ref(0)
let storys =ref('');
let flag = ref(false);
const fromdata=ref({});
const size = ref("default");


const multipleSelection = ref([]);
let psychologyanswerquestionList = ref([]);
const findpsychologyanswerquestionPage=() => {
  axios.get(
      '/api/psychologyAnswerQuestion/searchByName',
      {
        params: {
          pageNum: pageNum.value,
          pageSize: pageSize.value,
          storys:storys.value
        }
      }
  ).then(resp=>{
    console.log(resp)
    const pageInfo = resp.data.data;
    psychologyanswerquestionList.value = pageInfo.list;
    total.value = pageInfo.total;
    pageSize.value = pageInfo.pageSize;
    pageNum.value = pageInfo.pageNum;
  })
}
const xiugaiInfo = (info) => {
  flag.value = true;
  // 创建一个新对象，复制原对象的属性
  fromdata.value = { ...info };
  editEnable.value = false;
  name.value ='编辑'
}
const tijiao =async () => {
  flag.value = false;
  console.log(fromdata.value);
    const result = await axios.put("/api/psychologyAnswerQuestion/updatePsychologyAnswerQuestion", fromdata.value)
    if (result.data.code === 200) {
      findpsychologyanswerquestionPage()
    }


}

onMounted(() => {
  findpsychologyanswerquestionPage();
})

const sousuo = () => {
  findpsychologyanswerquestionPage();
}
const deleteInfo = (id) => {
  axios
      .delete("/api/psychologyAnswerQuestion/deletePsychologyAnswerQuestion/" + id)
      .then((resp) => {
        console.log(resp);
        findpsychologyanswerquestionPage();
      });
};


const handleSizeChange = () => {
  console.log("搜索条件：");
  console.log(storys.value);
  findpsychologyanswerquestionPage();
};

const handleCurrentChange = () => {
  console.log(pageNum.value);
  findpsychologyanswerquestionPage();
};

const handleSelectionChange = (val) => {
  const newval = val.map((item) => item.id);
  multipleSelection.value = newval;
};

</script>

<template>
问题标题
  <el-input style="width: 240px;margin: 0 10px;" placeholder="" v-model="storys"/>
  <el-button type="primary" @click="sousuo">搜索</el-button>
  <div>
    <div style="margin: 20px 0">
      <el-table
          :data="psychologyanswerquestionList"
          style="width: 100%"
          row-key="id"
          @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55" />
        <el-table-column label="ID" width="120" prop="id">

        </el-table-column>
        <el-table-column  label="用户编号"  prop="userId"/>
        <el-table-column  label="问题内容" prop="storys"/>
        <el-table-column  label="问题发布时间" prop="storyTime"/>
        <el-table-column  label="咨询师id" prop="consultantId"/>
        <el-table-column  label="问题回复" prop="reply"/>
        <el-table-column  label="回复时间" prop="replyTime"/>
        <el-table-column  label="操作">
          <template #default="scope">
            <div style="display: flex">
<!--              <el-button type="primary" style="margin: 0 20px; font-size: 15px;"size="large"  @click="bianji(scope.row)">编辑</el-button>-->
              <el-button type="primary" style="margin: 0 20px; font-size: 15px;"size="large"  @click="deleteInfo(scope.row.id)">删除</el-button>
              <el-button type="primary" style="margin: 0 20px; font-size: 15px;"size="large"  @click="xiugaiInfo(scope.row)">修改</el-button>
            </div>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div>
      <el-pagination
          v-model:current-page="pageNum"
          v-model:page-size="pageSize"
          :page-sizes="[5, 10, 20, 30, 40]"
          :size="size"
          :disabled="disabled"
          :background="background"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
      />
    </div>


    <!--  弹出层-->
    <div>
      <el-dialog v-model="flag" title="修改回复" width="700px" center>
        <el-form :model="fromdata" label-width="auto" style="max-width: 300px" :readonly="editEnable">
          <el-form-item label="内容">
            <el-input v-model="fromdata.reply" type="textarea" />
          </el-form-item>
        </el-form>
        <template #footer>
          <div class="dialog-footer">
            <el-button @click="centerDialogVisible = false">退出</el-button>
            <el-button type="primary" @click="tijiao">
              提交
            </el-button>
          </div>
        </template>
      </el-dialog>
    </div>
  </div>
</template>

<style scoped>

</style>
